<!DOCTYPE html>
<html>

<head>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
             pageEncoding="UTF-8"%>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1">
    <!-- Google Chrome Frame也可以让IE用上Chrome的引擎: -->
    <meta name="renderer" content="webkit">
    <!--国产浏览器高速模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="author" content="穷在闹市"/>
    <!-- 作者 -->
    <meta name="revised" content="穷在闹市.v3, 2019/05/01"/>
    <!-- 定义页面的最新版本 -->
    <meta name="description" content="网站简介"/>
    <!-- 网站简介 -->
    <meta name="keywords" content="搜索关键字，以半角英文逗号隔开"/>
    <title>穷在闹市出品</title>

    <!-- 公共样式 开始 -->
    <link rel="stylesheet" type="text/css" href="../css/base.css">
    <link rel="stylesheet" type="text/css" href="../fonts/iconfont.css">
    <script type="text/javascript" src="../framework/jquery-1.11.3.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../layui/css/layui.css">
    <script type="text/javascript" src="../layui/layui.js"></script>


    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
    <script src="framework/cframe.js"></script><!-- 仅供所有子页面使用 -->
    <!-- 公共样式 结束 -->

    <style>
        .layui-table img {
            max-width: none;
        }
    </style>

</head>

<body>
<div class="cBody">
    <div class="console">
        <form class="layui-form" action="TypeServiet?action=queryBName" method="post">
            <div class="layui-form-item">
                <div class="layui-input-inline">
                    <input type="text" name="name" required lay-verify="required" placeholder="输入商品名称"
                           autocomplete="off" class="layui-input">

                </div>
                <button class="layui-btn" lay-submit lay-filter="submitBut">检索</button>
            </div>

            <input type="hidden" id="count" value="${page.count}">
            <div>

                班级 <select id="mid">
                <option>请选择</option>
                <c:forEach var="modular" items="${modular}">
                    <option value="${modular.id }" style="width: 20px; height: 20px">${modular.name}</option>
                </c:forEach>
            </select>
                <form id="addForm" action="PostsServlet?action=add" method="post">
                    课程<select id="sid" name="sid">
                </select>
                </form>
            </div>
        </form>
        <script type="text/javascript">
            $(function() {
                $("#mid").change(
                    function() {
                        var mid = $("#mid").val();

                        $.ajax({
                            url : "/subject/querybyclassid",
                            type : "POST",
                            data : {
                                id : mid
                            },
                            success : function(result) {
                                var json = JSON.parse(result);
                                console.log(json);
                                var html = "";
                                for (var i = 0; i < json.length; i++) {
                                    html += "<option value='"+json[i].id+"'>"
                                        + json[i].name + "</option>"
                                }

                                $("#sid").html(html);
                                layui.form.render("select");
                            }
                        });
                    })

            })
        </script>

        <script>
            layui.use('form', function () {
                var form = layui.form;

                //监听提交
                form.on('submit(submitBut)', function (data) {
                    layer.msg(JSON.stringify(data.field));
                    return true;
                });
            });

            layui.use('form', function () {
                var form = layui.form;

                //监听提交
                form.on('submit(submitBut)', function (data) {
                    layer.msg(JSON.stringify(data.field));
                    return false;
                });


            });
        </script>
    </div>

    <table class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>老师姓名</th>
            <th>性别</th>
            <th>老师微信</th>
            <th>老师联系方式</th>
            <th>老师身份证</th>
            <th>老师职务</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody id="tbody">
        <c:forEach var="teacher" items="${teachers}">
            <tr>
                <td>${teacher.tid}</td>
                <td>${teacher.tname}</td>
                <td>${teacher.tsex}</td>
                <td>${teacher.twx}</td>
                <td>${teacher.tphone}</td>
                <td>${teacher.tcard}</td>
                <td>
                    <c:if test="${teacher.role.id==0}">待审核</c:if>
                    <c:if test="${teacher.role.id==1}">学校领导人</c:if>
                    <c:if test="${teacher.role.id==2}">专业老师</c:if>
                    <c:if test="${teacher.role.id==3}">班主任</c:if>
                </td>
                <td>
                    <c:if test="${teacher.tstatus==0}">禁用</c:if>
                    <c:if test="${teacher.tstatus==1}">启用</c:if>
                </td>
                <td>
                    <a class="layui-btn layui-btn-xs" href="/teacher/queryById?&id=${teacher.tid}">修改</a>
                    <a class="layui-btn layui-btn-xs" href="/teacher/updateStatus?status=0&id=${teacher.tid}">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <!-- layUI 分页模块 -->
    <div class="h_55"></div>
    <div id="pages"></div>
    <script>
        layui.use('laypage', function () {
            var laypage = layui.laypage;
            // int i=0;
            //总页数大于页码总数
            laypage.render({
                elem: 'pages'
                , count: $("#count").val()
                ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                ,limit:3
                , limits:['2','5','8']
                , jump: function (obj) {
                    // if(0==i++)return;

                    var curr = obj.curr;
                    var limi = obj.limit;
                    $.ajax({
                        type:"post",
                        url:"TypeServiet?action=ajaxquery",
                        data:{"currentPage":curr,"size":limi},
                        success: function (data) {
                            console.log(data);
                            var js =  JSON.parse(data);
                            console.log(js);
                            var html="";
                            for(var i=0;i<js.length;i++){
                                html+="<tr>"
                                html+="<td>"+js[i].id+"</td>"
                                html+="<td>"+js[i].name+"</td>"
                                html+="<td>"+js[i].status+"</td>"
                                html+="<td><a class='layui-btn layui-btn-xs' href='TypeServiet?action=updatepage&id="+js[i].id+"'>修改</a><a class='layui-btn layui-btn-xs' href='TypeServiet?action=delete&id="+js[i].id+"'>删除</a></td>"
                                html+="</tr>"
                            }
                            $("#tbody").html(html);
                        }

                    });
                }
            });
        });

        //修改规格
        function specificationsBut() {
            layui.use('layer', function () {
                var layer = layui.layer;

                //iframe层-父子操作
                layer.open({
                    type: 2,
                    area: ['70%', '60%'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: 'specifications_list.html'
                });
            });

        }

        //修改按钮
        var updateFrame = null;

        function updateBut() {
            layui.use('layer', function () {
                var layer = layui.layer;

                //iframe层-父子操作
                updateFrame = layer.open({
                    title: "商品信息修改",
                    type: 2,
                    area: ['70%', '60%'],
                    scrollbar: false,	//默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
                    maxmin: true,
                    content: 'goods_update.html'
                });
            });

        }
    </script>
</div>
</body>

</html>